import axios from "axios";
const http = axios.create({
    baseURL: "http://nefuswzl.top:3000/",
    withCredentials: true,
    timeout: 10000
})

// 请求拦截
http.interceptors.request.use(config => {
    /*携带token验证*/
    const token = sessionStorage.getItem('token');
    if(token){
        config.headers.token = token;
    }
    return config
}, err => {
    throw new Error(err)
})


// 响应拦截
http.interceptors.response.use(res => {
    return res.data
}, err => {
    throw new Error(err)
})

function request({ method = 'get', url, data = {}, params = {} }) {
    return http({
        method,
        url,
        data,
        params
    })
}

export default request;
